package com.ch.dream.activity.main;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

import com.ch.dream.R;
import com.ch.dream.base.BaseActivity;
import com.ch.dream.common.CommonUserInfo;
import com.ch.dream.logic.main.MainMenuLogic;
import com.ch.dream.tools.UtilTools;
import com.ch.dream.tools.ViewTools;

public class MainMenuActivity extends BaseActivity {

	private MainMenuLogic logic;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try{
			logic = new MainMenuLogic(this);
			logic.setViews(R.layout.m_menu);
		}catch (Exception e) {
			e.printStackTrace();
			Log.e("activity",e.toString());
		}
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode==KeyEvent.KEYCODE_BACK){
			ViewTools.showConfirm(this, "提示信息", "确认要退出吗？", "确定", "取消", 
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							int id = android.os.Process.myPid();
							android.os.Process.killProcess(id);
						}
					}, 
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
						}
			});
			return false;
		}else{
			return super.onKeyDown(keyCode, event);
		}
		
	}
	
	@Override
	protected void handlerTitleBarEvent(int mode) {
		if(mode == LEFT_BUTTON){
			Intent intent =new Intent(this,RegisterActivity.class);
			startActivity(intent);
		}else if(mode == RIGHT_BUTTON){
			Intent intent =new Intent(this,LoginActivity.class);
			startActivity(intent);
		}
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		if(UtilTools.isNotNullOrEmpty(CommonUserInfo.userId)){
			this.setTitle("false","故事梦", "false");
		}else{
			this.setTitle("注册","故事梦", "登录");
		}
		logic.init();
	}
}
